﻿<%@ Page Title="Xtablish CRM / Edit Company" MasterPageFile="~/Site.Master" Language="C#" AutoEventWireup="true" CodeBehind="EditCompany.aspx.cs" Inherits="Web.Edit.EditCompany" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<asp:Content ID="Content1" ContentPlaceHolderID="headContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Con1" runat="server">
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">           
            function OnClientClose(oWnd, args) {
                //get the transferred arguments
                var arg = args.get_argument();
                if (arg) {
                    var searchType = arg.SearchType;
                    if (searchType == "Organization") {
                        var orgName = arg.OrgName;
                        var orgID = arg.OrgID;
                        document.getElementById('<%= hdntxtOrgName.ClientID %>').value = orgName;
                        document.getElementById('<%= hdntxtOrgID.ClientID %>').value = orgID;
                        document.getElementById('<%= txtSubsidary.ClientID %>').value = orgName;
                    }
                }
            }
            function clearOrgName() {
                document.getElementById('<%= txtSubsidary.ClientID %>').value = null;
                document.getElementById('<%= hdntxtOrgID.ClientID %>').value = null;
                document.getElementById('<%= hdntxtOrgName.ClientID %>').value = null;
            }
            function disableKeyPress(evt) {
                return false;
            }
            function CancelClick() {
                window.location.assign(document.getElementById('<%= hdntxtPrevPage.ClientID %>').value);
            }
            function WebForm_OnSubmit() {
                if (typeof (ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) {
                    $("#validation_dialog").dialog({
                        title: "Validation Error!",
                        modal: true,
                        resizable: false,
                        buttons: {
                            Close: function () {
                                $(this).dialog('close');
                            }
                        }
                    });
                    return false;
                }
                return true;
            }
            $.verify.addRules({
                websiteUrlValidate: function (w) {
                    var regexp = /^http[s]*\:\/\/[wwW]{3}\.+[a-zA-Z0-9]+\.[a-zA-Z]{2,3}.*$|^http[s]*\:\/\/[^w]{3}[a-zA-Z0-9]+\.[a-zA-Z]{2,3}.*$|http[s]*\:\/\/[0-9]{2,3}\.[0-9]{2,3}\.[0-9]{2,3}\.[0-9]{2,3}.*$/;
                    var url = w.val();
                    var urlvalidate = document.getElementById('<%= txtComWebsiteURL.ClientID %>');
                    if (!regexp.test(url)) {
                        urlvalidate.value = null;
                        return "Invalid URL.";
                    }
                    urlvalidate.value = "website";
                }
            });
            $.verify.addRules({
                primaryEmailValidate: function (w) {
                    var regexp = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
                    var url = w.val();
                    var urlvalidate = document.getElementById('<%= txtPrimaryEmailValidate.ClientID %>');
                    if (!regexp.test(url)) {
                        urlvalidate.value = null;
                        return "Invalid email address.";
                    }
                    urlvalidate.value = "email";
                }
            });
            $.verify.addRules({
                secondaryEmailValidate: function (w) {
                    var regexp = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
                    var url = w.val();
                    var urlvalidate = document.getElementById('<%= txtSecondaryEmailValidate.ClientID %>');
                    if (!regexp.test(url)) {
                        urlvalidate.value = null;
                        return "Invalid email address.";
                    }
                    urlvalidate.value = "email";
                }
            });
            function CheckNull() {
                var comwebsite = document.getElementById('<%= txtCompanyWebsite.ClientID %>');
                if (comwebsite.value.trim() == "")
                    document.getElementById('<%= txtComWebsiteURL.ClientID %>').value = "website";
                var priemail = document.getElementById('<%= txtPrimaryEmail.ClientID %>');
                if (priemail.value.trim() == "")
                    document.getElementById('<%= txtPrimaryEmailValidate.ClientID %>').value = "email";
                var secemail = document.getElementById('<%= txtSecondaryEmail.ClientID %>');
                if (secemail.value.trim() == "")
                    document.getElementById('<%= txtSecondaryEmailValidate.ClientID %>').value = "email";
            }
        </script>
    </telerik:RadCodeBlock>
    <asp:HiddenField ID="hdntxtOrgName" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtOrgID" runat="server"></asp:HiddenField>
    <asp:HiddenField ID="hdntxtPrevPage" runat="server"></asp:HiddenField>
    <div class="register" id="divContent" runat="server" style="display: block">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-6">
                    <h3>Edit Company</h3>
                </div>
                <div class="col-md-6 btn-edit">
                    <asp:LinkButton id="btnTop_Delete" runat="server" type="button" class="btn btn-defaul" OnClick="btn_Delete_ServerClick"
                        OnClientClick="return radConfirmDelete(this, 'Are you sure you want to delete this company ?');">
                        <img src="../Images/delete.png" style="width: 18px; height: 18px" />
                        Delete
                    </asp:LinkButton>
                    <asp:LinkButton id="btnTop_Save" type="button" runat="server" class="btn btn-defaul" OnClick="btn_Save_Click">
                        <img src="../Images/save.png" style="width: 18px; height: 18px" />
                        Save
                    </asp:LinkButton>
                    <div id="validation_dialog" style="display: none">
                        <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
                    </div>
                    <asp:LinkButton id="btnTop_Cancel" type="button" runat="server" class="btn btn-defaul" OnClientClick="CancelClick()">
                        <img src="../Images/back.png" style="width: 18px; height: 18px" />
                        Back
                    </asp:LinkButton>
                </div>
            </div>

            <div class="row">
                <div class="edit-form highlight">
                    <div class="control-group">
                        <h4>Company Details</h4>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Company Name<span class="red-star">*</span></label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtOrganizationName" runat="server" class="form-control" data-validate="required" />
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" Display="None" ControlToValidate="txtOrganizationName"
                                        runat="server" ErrorMessage="Company Name is required."></asp:RequiredFieldValidator>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Company Website </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtCompanyWebsite" runat="server" class="form-control" data-validate="websiteUrlValidate"/>
                                    <div style="display: none">
                                        <asp:TextBox ID="txtComWebsiteURL" runat="server" class="form-control" Text="website" />
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" Display="None" ControlToValidate="txtComWebsiteURL"
                                            runat="server" ErrorMessage="Invalid Company Website URL."></asp:RequiredFieldValidator>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Contact Number </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtContactNumber" runat="server" class="form-control" />
                                </div>
                            </div>

                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Ticker Symbol</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtTickerSymbol" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Fax </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtFax" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Subsidary</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtSubsidary" runat="server" class="form-control form-fl" onkeypress="return disableKeyPress(event)" />
                                    <div class="btn-sl" style="padding-top:2px">
                                        <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="openWin('../../SearchPopUp/Organization.aspx', 'rwOrganization'); return false;" ToolTip="Search">
                                            <img src="../Images/search.png" style="width: 18px; height: 18px" />
                                        </asp:LinkButton>
                                        <asp:LinkButton ID="LinkButton2" runat="server" OnClientClick="clearOrgName();return false;" ToolTip="Clear">
                                            <img src="../Images/delete.png" style="width: 16px; height: 16px" />
                                        </asp:LinkButton>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Secondary Phone </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtSecondaryPhone" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Employees </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtEmployees" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Primary Email </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtPrimaryEmail" runat="server" class="form-control" data-validate="primaryEmailValidate"/>
                                    <div style="display: none">
                                        <asp:TextBox ID="txtPrimaryEmailValidate" runat="server" class="form-control" Text="email" />
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" Display="None" ControlToValidate="txtPrimaryEmailValidate"
                                            runat="server" ErrorMessage="Invalid Primary Email Address."></asp:RequiredFieldValidator>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Secondary Email </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtSecondaryEmail" runat="server" class="form-control" data-validate="secondaryEmailValidate"/>
                                    <div style="display: none">
                                        <asp:TextBox ID="txtSecondaryEmailValidate" runat="server" class="form-control" Text="email" />
                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" Display="None" ControlToValidate="txtSecondaryEmailValidate"
                                            runat="server" ErrorMessage="Invalid Secondary Email Address."></asp:RequiredFieldValidator>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Ownership </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtOwnership" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Industry </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <telerik:RadComboBox ID="DdlIndustry" runat="server" DataTextField="ORGANIZATION_INDUSTRY_NAME" DataValueField="ID"
                                        Width="60%" Filter="StartsWith" MaxHeight="700px" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Rating </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <telerik:RadComboBox ID="ddlRating" runat="server" DataTextField="ORGANIZATION_RATING_NAME" DataValueField="ID"
                                        Width="60%" Filter="StartsWith" MaxHeight="700px" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Type </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <telerik:RadComboBox ID="ddlType" runat="server" DataTextField="ORGANIZATION_TYPE_NAME" DataValueField="ID"
                                        Width="60%" Filter="StartsWith" MaxHeight="700px" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group" id="divAssignTo" runat="server">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Company Registration Number </label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtCompanyRegistrationNumber" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Assigned To<span class="red-star">*</span></label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <telerik:RadComboBox ID="ddlAssignedTo" runat="server"
                                        Width="60%" Filter="StartsWith" MaxHeight="700px" />
                                </div>
                            </div>
                        </div>                        
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
            <!-- end row 1 -->
            <div class="row">
                <div class="edit-form highlight">
                    <div class="control-group">
                        <h4>Address Details</h4>
                    </div>
                    <!--<div class="control-group">
                        <div class="col-md-6">
                        </div>
                        <div class="clearfix"></div>
                    </div>-->
                    <div class="control-group">
                        <div class="col-md-6 distance-control sd-control">
                            <div class="col-md-4">
                                <label class="control-label">Office Address</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtOfficeAddress" runat="server" TextMode="MultiLine" class="form-control" Rows="1"></asp:TextBox>
                                    <label id="txtCopyHomeAddress" class="control-label" onclick="lbCopyHomeAddress_Click" runat="server">Copy Home Address</label>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 distance-control sd-control">
                            <div class="col-md-4">
                                <label class="control-label">Home Address</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtHomeAddress" runat="server" TextMode="MultiLine" class="form-control" Rows="1"></asp:TextBox>
                                    <label id="txtCopyOfficeAddress" class="control-label" onclick="lbCopyOfficeAddress_Click " runat="server">Copy Office Address</label>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Office PO Box</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtOfficePOBox" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>


                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Home PO Box</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtHomePOBox" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>

                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Office City</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtOfficeCity" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>


                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Home City</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtHomeCity" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>

                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Office State</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtOfficeState" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Home State</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtHomeState" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Office Postal Code</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtOfficePostalCode" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Home Postal Code</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtHomePostalCode" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="control-group">
                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Office Country</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtOfficeCountry" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6 distance-control">
                            <div class="col-md-4">
                                <label class="control-label">Home Country</label>
                            </div>
                            <div class="col-md-8">
                                <div class="controls">
                                    <asp:TextBox ID="txtHomeCountry" runat="server" class="form-control" />
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
            <!-- end row 4 -->
            <div class="row">
                <div class="col-md-12 btn-edit">
                    <asp:LinkButton id="btnBottom_Delete" runat="server" type="button" class="btn btn-defaul" OnClick="btn_Delete_ServerClick"
                        OnClientClick="return radConfirmDelete(this, 'Are you sure you want to delete this company ?');">
                        <img src="../Images/delete.png" style="width: 18px; height: 18px" />
                        Delete
                    </asp:LinkButton>
                    <asp:LinkButton id="btnBottom_Save" type="button" class="btn btn-defaul" runat="server" OnClick="btn_Save_Click">
                        <img src="../Images/save.png" style="width: 18px; height: 18px" />
                        Save
                    </asp:LinkButton>
                    <asp:LinkButton id="btnBottom_Cancel" runat="server" type="button" class="btn btn-defaul" OnClientClick="CancelClick()">
                        <img src="../Images/back.png" style="width: 18px; height: 18px" />
                        Back
                    </asp:LinkButton>
                </div>
            </div>
        </div>
    </div>
    <div class="register" id="divError" runat="server" style="display: none">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-12">
                    This company is not exist, click <a href="Companies.aspx"><strong>here</strong></a> to go back Company list.
                </div>
            </div>
        </div>
    </div>
</asp:Content>
